import java.util.Optional;

public class MapFlatMap {
   public static void main(String[] args) {
        Student student = new Student(0, "Alice", 20);
        Optional<Student> optional = Optional.ofNullable(student);      
        Optional<String> s1 = optional.flatMap(stu-> getStuName(stu));
        Optional<Optional<String>> s2 = optional.map(stu-> getStuName(stu));
   } 

   public static Optional<String> getStuName(Student student) {
      return Optional.ofNullable(student).map(s -> s.getName());
   }
}
